import json

from tensorflow import keras

from src.utils.config import config
from src.utils.model_utils import get_level_id_mapping,get_oversampling_product_id

GET_OVERSAMPLING_PRODUCT_ID=get_oversampling_product_id(category=1,date='2019-01-01')
# 环保机等级模板ID
EVN_TEMPLATE_ID = '408'
# 列名映射
MOBILE_COLUMNS_MAPPING = {'内存': 'memory', '苹果保修期时长': 'guarantee','保修情况(华为)':'guarantee', '存储容量': 'storage', '网络制式': 'networks',
                          '购买渠道': 'purchase_way', '机身颜色': 'color', '小型号': 'small_version'}
# 等级ID和名称映射
MOBILE_LEVEL_ID_MAPPING = get_level_id_mapping(1)

# 模型特征
MOBILE_FEATURES = ['product_name', 'product_brand_name', 'product_level_name', 'product_level_template_id',
                   'memory', 'guarantee', 'storage', 'networks', 'purchase_way', 'period', 'small_version','body_color']

MOBILE_FEATURES_NEW = ['product_name', 'product_brand_name', 'product_level_name', 'product_level_template_id',
                   'memory', 'guarantee', 'storage', 'networks', 'purchase_way', 'period', 'small_version','color','body_color']

# 模型保存时间
KEEP_MODEL_DAYS = 180

OVERSAMPLING=100

# 模型推送到的服务器
MODEL_PUSH_SERVERS = json.loads(config.get_config('model', 'model_servers'))
# 模型API接口
MODEL_SERVER_PORTS = json.loads(config.get_config('model', 'model_server_ports'))

# 模型路径
MODEL_DIR = 'models/mobile/'
MODEL_DATA = 'mobile_train_data.pkl'

# 模型名称
MODEL_FILE_NAME = 'mobile_price.h5'
MOBILE_OHE_NAME = 'mobile_ohe.pkl'
MOBILE_SCALER_NAME = 'mobile_scaler.pkl'
MOBILE_PRODUCT_OHE_NAME = 'mobile_product_ohe.pkl'
# 模型数据的时间跨度
MODEL_DAYS = 42
# 近期加权时间
RECENT_DAYS = 3
EPOCHS=10
BATCHSIZE=1024

# 计算历史均价周期
MOBILE_HISTORY_AVG_PRICE_DAYS = 7
MOBILE_HISTORY_AVG_PRICE_PREFIX = 'mhap_'
# 历史均价缓存时长
MOBILE_HISTORY_CACHE_TIME = 60 * 60 * 36

# 模型早停配置
early_stop = keras.callbacks.EarlyStopping(monitor='loss', patience=10)
# 模型callback设置
model_callbacks = [early_stop]
# 荣耀AB测试，sku_id列表
# ABT_RY_sku_list = [231702,231705,231701,231704,231700,271671,276644,276646,276649,276643,276645,276648,276642,281581,10569,10574,59939,59273,107181,91568,107182,91569,91567,268047,268046,65928,65934,65933,92919,83926,100750,100758,100751,100755,100759,100760,100753,100757,264852,264846,264850,264848,264874,184679,184676,264870,184674,264892,184886,184673,184677,264896,264233,184688,184859,112018,111436,111437,118629,89194,188483,188479,188482,270518,121305,121307,121304,121306,264541,91602,122028,110299,187582,112705,110294,110302,110298,110300,110293,110301,187570,112744,112765,280055,278147,265578,265582,276528,276538,276540,91581,110682,110680,110679,10604,78749,188363,91613,122341,122276,105747,188568,106389,106391,106386,106390,123630,118362,114275,114273,114272,113784,113783,111977,266858,266854,266861,269555,187258,187254,187256,187257,264367,115202,122060,115206,115190,115198,122072,120012,115194,271665,10288,109176,112706,112752,188359,121820,186315,268516,266863,264366,115186,120008,266817,283192,10360,10250,268049,112703,279896,91544,188567,268495,266855,115189,271663,281579,273403,187596,112748,265581,120226,120009,283195,281584,269932,112704,91565,123658,264904,113234,188361,278214,188357,240159,283190,273760,113661,271667,123629,115181,283188,109173,284222,112739,91586,284242,280130,271661,283184,231723,188360,279893,266899,264362,123634,115205,120010,286159,286521,97751,185249,123463,283135,122080,65932,121193,123346,287344,264903,187576,123659,282129,110677,272414,121603,287349,264228,270508,187564,231720,121602,278146,283530,186612,279905]
ABT_RY_sku_list = [230084,704462,122076,279897,112747,632316,573882,266853,91590,534436,110681,540814,305725,186624,276660,266412,554996,536034,308590,114739,271664,282194,184860,534440,112700,113233,184498,283540,516146,649043,512754,283557,450436,704465,115274,704454,230229,268048,286160,94169,279894,112707,273762,719979,264882,308589,230228,188561,270528,573883,100756,264234,286161,112729,279895,117566,280131,266898,266818,271675,537061,283139,123653,270522,272413,112702,450440,516152,278605,115185,286512,283141,277075,264868,305727,276535,512377,112740,658763,283547,554995,268496,112766,120037,120030,649041,115184,268513,704464,106847,109175,534437,231721,280924,120022,649032,188364,280925,287346,287345,536023,632318,112751,704460,91584,272717,273761,264887,448390,268515,264369,649040,704456,112727,187382,534439,516145,573881,537060,269927,91605,230256,536024,308587,230261,573880,107981,512752,450441,450435,266359,448394,186611,264876,91591,272714,283536,269929,632320,121046,287250,91571,268050,283189,534438,120016,450442,283128,649038,649035,121604,120014,286158,273763,264888,278602,704458,536018,264900,186614,281580,277792,91570,283560,269553,269931,266357,268517,286509,279892,280929,122147,122155,281583,536030,113235,105273,286506,271679,280054,649044,270521,188569,534441,91540,98493,98492,91546,78746,91561,91538,184681] 